package org.eproject.core.well.command;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.eproject.core.well.delegate.Smodulelist;
import org.eproject.core.well.delegate.UserDeleGate;
import org.eproject.core.well.exception.CommandException;
import org.eproject.core.well.exception.DeleGateException;
import org.eproject.core.well.exception.FactoryException;
import org.eproject.core.well.factory.Simplefactory;
import org.eproject.core.well.viewhelp.Helper;

public class Grantcommand implements ICommand{

	public String execute(Helper h) throws CommandException {
		HttpServletRequest req = h.getReq();
		HttpServletResponse res = h.getRes();
		HttpSession session = req.getSession();
		UserDeleGate ud = null;
		Smodulelist list = null;
		try {
			ud = (UserDeleGate)Simplefactory.creatorBean("userdelegate");
			Map userinfo = (Map)session.getAttribute("userinfo");
			list = ud.getSmodule(Integer.valueOf(userinfo.get("uid").toString()));
			session.setAttribute("onelevelmodule",list.getOne());
			session.setAttribute("twolevelmodule",list.getTwo());
			session.setAttribute("thirlevelmodule",list.getThir());
			return "/eproject/main/main.jsp";
		} catch (FactoryException e) {
			e.printStackTrace();
			throw new CommandException(e);
		} catch (DeleGateException e) {
			e.printStackTrace();
			throw new CommandException(e);
		}
	}

}
